﻿using Bootstrap.Admin.Models;
using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using Bootstrap.DataAccess.Model;

namespace Bootstrap.Admin.Controllers
{
    /// <summary>
    /// Account controller.
    /// </summary>
    [Route("iifoxHandler/[controller]")]
    [ApiController]
    public class AnswerController : ControllerBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
       // public ActionResult Index() => View(new NavigatorBarModel(this));
        [HttpGet]
        public QueryData<object> Get([FromQuery]QueryAnswerOption value)
        {
            return value.RetrieveData();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        [HttpDelete]
        [ButtonAuthorize(Url = "~/Admin/Users", Auth = "del")]
        public bool Delete([FromBody]IEnumerable<string> value)
        {
            return AnswerHelper.Delete(value);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpOptions]
        public string Options()
        {
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        [HttpPut]
        public JsonResult Put([FromBody]Answer value, [FromQuery]string fq)
        {
            //return 

            AnswerHelper.Save(value);

            return new JsonResult(value);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public JsonResult Get(string id)
        {
            if (id == "#") return new JsonResult("");

            var an = AnswerHelper.Retrieves();
            if (!string.IsNullOrEmpty(id))
            {
                an = an.Where(t => t.AE_ID == id);

            }

            return new JsonResult(an.Single());//new JsonResult(an).ToString();
        }
    }
}
